{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Run this script from the terminal as follows:\n",
    "# python compress.py input_dir output_dir\n",
    "# replacing input_dir by the directory containing the *.tif images \n",
    "# to compress, and output_dir by the destination folder\n",
    "\n",
    "# Requires GDAL installed in the machine!\n",
    "\n",
    "\n",
    "\n",
    "import os\n",
    "import subprocess\n",
    "import sys\n",
    "\n",
    "input_dir = 'D:/Data/AerialImageDataset/test/integrated'\n",
    "output_dir = 'D:/Data/AerialImageDataset/test/compressed'\n",
    "\n",
    "for file in os.listdir(input_dir):\n",
    "    if file.endswith(\".tif\"):\n",
    "        input_file = os.path.join(input_dir,file)\n",
    "        output_file = os.path.join(output_dir,file)\n",
    "        command = \"gdal_translate --config GDAL_PAM_ENABLED NO -co COMPRESS=CCITTFAX4 -co NBITS=1 \"+input_file+\" \"+output_file\n",
    "        print(command)\n",
    "        subprocess.call(command,shell=True)\n",
    "\n",
    "print \"Done!\"\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
